package com.rpframework.website.friendly.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.friendly.dao.IAboutusDao;
import com.rpframework.website.friendly.domain.Aboutus;
import com.rpframework.website.friendly.util.HConstants;

@Service
public class AboutusService extends BaseService{
	public @Resource IAboutusDao iDao;
	public Pager<Aboutus> getPager(Pager<Aboutus> pager) {
		long startTime = System.currentTimeMillis();
		List<Aboutus> list = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}

	public boolean doSaveOrUpdate(Aboutus t) {
		if(NumberUtils.isValid(t.getId())){
			t.setModifyTime(System.currentTimeMillis() / 1000);
			return iDao.update(t);
		}
		t.setCreateTime(System.currentTimeMillis()/1000);
		return insert(t);
	}

	public boolean doUpdateState(Integer id) {
		if(NumberUtils.isValid(id)){
			Aboutus t = iDao.select(id);
			if(t.getState() == HConstants.EntityState.STATE_NORMAL){
				t.setState(HConstants.EntityState.STATE_DISABLE);
			}else{
				t.setState(HConstants.EntityState.STATE_NORMAL);
			}
			return iDao.update(t);
		}
		return false;
	}

	public Aboutus selectByType(Integer type) {
		return iDao.selectByType(type);
	}
}
